package com.yf.ma;

import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.Opcodes;

public class OOMTest extends ClassLoader {
    public static void main(String[] args) {
        int i = 0;
        try {
            OOMTest ot = new OOMTest();

            for (int j = 0; j < 10000; j++) {
                // 创建ClassWriter对象，用于生成类的十进制字节码
                ClassWriter cw = new ClassWriter(0);
                cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, "Class" + j, null,
                        "java/lang/Object", null);

                byte[] code = cw.toByteArray();
                ot.defineClass("Class" + j, code, 0, code.length);
                i++;
            }
        } finally {
            System.out.println(i);
        }
    }
}
